<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let persons = [
        { username: 'xiaoming1', password: '1111' },
        { username: 'xiaoming2', password: '222' },
        { username: 'xiaoming3', password: '33333' },
      ];
      //   let user = { username: 'xiaoming11', password: '11111' };
        let user = { username: 'xiaoming1', password: '1111' };
      //   let user = { username: 'xiaoming1', password: '11111' };
      //   登录;
      let index = persons.some(
        (item) =>
          item.username == user.username && item.password == user.password
      );
      if (index) {
        console.log('登录成功');
      } else {
        console.log('用户名和密码错误');
      }

      //注册
      let index1 = persons.findIndex((item) => item.username == user.username);
      let persons1 = [...persons];
      if (index1 == -1) {
        persons1.push(user);
      } else {
        console.log('用户已注册');
      }
      console.log(persons1);
      console.log(persons);
    </script>
  </body>
</html>
